/**
  * Copyright (c) CSIRO Australia, 2009
  *
  * @author $Author: jia020 $
  * @version $Id: WFAdminPanel.java 643 2009-05-20 00:20:55Z jia020 $
  */
package au.csiro.nt.pdsp.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.data.Record;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarButton;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.layout.FitLayout;

/**
 * Class to create a panel for Workflow admin.
 */
public class WFAdminPanel extends Panel {
	private EventHandler eventHandler = null;
	private final PDQueryServiceAsync service = GWT.create(PDQueryService.class);		
	private DynamicGrid grid = null;
	private TextField tfLogs = null; 
	/**
	 * Constructor for WFAdminPanel
	 * @param eventHandler for callback.
	 * @param xmlData xml formated workflows data.
	 */	
	public WFAdminPanel(EventHandler eventHandler, String xmlData) {
		super();
		this.eventHandler = eventHandler;
		this.setBorder(false);
		this.setPaddings(5);
		this.setLayout(new FitLayout());

		grid = new DynamicGrid(xmlData);
		Toolbar toolbar = new Toolbar();  
		ToolbarButton button = new ToolbarButton("Show Logs", new ButtonListenerAdapter() {  
		    public void onClick(Button button, EventObject e) {  	
		    	getLogs();
		    }  
		});  			
		toolbar.addButton(button); 	
		
		tfLogs = new TextField("Logs", "email", 610);
		
		this.add(grid);		
		this.add(toolbar);		
		this.add(tfLogs);		
	}
	private void getLogs() {
		if (grid == null) 
			return;
		final Record selectedRecord = grid.getSelectionModel().getSelected();
		if (selectedRecord == null) 
			return;
	  String logs = selectedRecord.getAsString("logs");
	  tfLogs.setValue(logs);
	}
}
